package com.fanqwz.kotlinmvvm.ui.fragment.main

import android.databinding.DataBindingUtil
import android.view.LayoutInflater
import android.view.View
import com.fanqwz.kotlinmvvm.R
import com.fanqwz.kotlinmvvm.databinding.FragmentMainBinding
import com.fanqwz.kotlinmvvm.presenter.viewmodel.IModel
import com.fanqwz.kotlinmvvm.presenter.viewmodel.IViewModel
import com.fanqwz.kotlinmvvm.ui.activity.login.ILoginView
import com.fanqwz.kotlinmvvm.ui.compositor.ViewCompositor
import com.fanqwz.kotlinmvvm.view.BaseView
import javax.inject.Inject

/**
 * Created by fanqwz on 2018/3/7.
 */
class MainFragmentView @Inject constructor(): BaseView<FragmentMainBinding>(), ILoginView {
    override fun <T : IModel> onBind(viewmodel: IViewModel<T>) {
        binding.user = viewmodel.bind()
    }

    override fun onLoginEventCallBack(callback: (name: String, passwd: String) -> Unit) {
    }

    override val viewCompositor: ViewCompositor
        get() = object : ViewCompositor() {
            override fun inflateView(layoutInflater: LayoutInflater): View? {
                binding = DataBindingUtil.inflate(
                        layoutInflater,
                        R.layout.fragment_main,
                        null,
                        false,
                        databindingComponent)!!
                return binding.root
            }

        }
}